package org.codetranslators.compiler.abstractassembly;


import org.codetranslators.common.Label;
import org.codetranslators.common.Temp;

public class AssemMemory extends AssemExp
{
	private AssemExp exp;
	
	public AssemMemory(AssemExp e) 
	{
		exp = e;
	}
	
	public AssemExpList children() 
	{
		return new AssemExpList(exp,null);
	}
	
	public AssemExp getMemExp()
	{
		return exp;
	}
	
	public AssemType translateToCJump(Label labelTrue, Label labelFalse)
	{
		
		return exp.translateToCJump(labelTrue, labelFalse);
	}
	
	/**
	* This function will coerce this binary operator expression into an int type,
	* by creating a temporary holding an int value
	*/
	public AssemType translateToIntType()
	{
		AssemTemp temp = new AssemTemp(new Temp());
		AssemMove move = new AssemMove(temp, this);
		AssemSeqExp seqExp = new AssemSeqExp(move, temp);
		
		return seqExp;
	}
		
	public int getType()
	{
		return INT_TYPE;
	}
	
	public String getDescription()
	{
		return "Memory";
	}
	
	public AssemExp build(AssemExpList list)
	{
		return new AssemMemory(list.getHead());
	}
	
	public AssemSeqExp canonize()
	{
		AssemSeqExp seMemExp = exp.canonize();
		AssemStm seMemExpStm = seMemExp.getStm();
		AssemExp seMemExpExp = seMemExp.getExp();

		return new AssemSeqExp(seMemExpStm, new AssemMemory(seMemExpExp));	
	}
	
	public int getExpType()
	{
		return AssemExp.MEM;
	}
}
